//
//  TTToBarView.swift
//  TTWeibo
//
//  Created by 陶宏路 on 16/7/23.
//  Copyright © 2016年 陶路路. All rights reserved.
//

import UIKit

class TTToBarView: UIView {
    
    var leftButton:UIButton?
    
    var centerButton:UIButton?
    
    var rightButotn:UIButton?
    
    var ttcellHomeModel:TTHomeCellModel?{
        
        didSet{
            
            leftButton?.setTitle(ttcellHomeModel?.reposts_count, forState: UIControlState.Normal)
            centerButton?.setTitle(ttcellHomeModel?.comments_count, forState: UIControlState.Normal)
            rightButotn?.setTitle(ttcellHomeModel?.attitudes_count, forState: UIControlState.Normal)
            
        }
    }

    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        backgroundColor = UIColor.whiteColor()
        setUpUI()
    }

    func setUpUI(){
        
        leftButton = getButton("转发", image: "timeline_icon_retweet")
        centerButton = getButton("评论", image: "timeline_icon_comment")
        rightButotn = getButton("赞", image: "timeline_icon_unlike")
        let lineImage = getLineImage()
        let lineImages = getLineImage()
        
        addSubview(leftButton!)
        addSubview(centerButton!)
        addSubview(rightButotn!)
        addSubview(lineImage)
        addSubview(lineImages)
        
        centerButton!.snp_makeConstraints { (make) -> Void in
            
            make.center.equalTo(self)
            make.height.equalTo(self)
//            make.width.equalTo(80)
        }
       
        leftButton!.snp_makeConstraints { (make) -> Void in
            
            make.centerY.equalTo(centerButton!)
            make.height.width.equalTo(centerButton!)
            make.trailing.equalTo(centerButton!.snp_leading)
            make.leading.equalTo(self)
        }
        
        rightButotn!.snp_makeConstraints { (make) -> Void in
            
            make.centerY.equalTo(centerButton!)
            make.width.height.equalTo(centerButton!)
            make.leading.equalTo(centerButton!.snp_trailing)
            make.trailing.equalTo(self)
        }
        
        lineImage.snp_makeConstraints { (make) -> Void in
            
            make.centerYWithinMargins.equalTo(centerButton!)
            make.leading.equalTo(leftButton!.snp_trailing)
            
        }
        
        lineImages.snp_makeConstraints { (make) -> Void in
            
            make.centerYWithinMargins.equalTo(lineImage)
            make.leading.equalTo(centerButton!.snp_trailing)
            
        }
        
    
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}


extension TTToBarView{
    
    func getButton(title:String,image:String)->UIButton{
        
        let button = UIButton()
        button.setTitle(title, forState: UIControlState.Normal)
        button.setTitleColor(UIColor.lightGrayColor(), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: image), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        return button
    }
    
    func getLineImage()->UIImageView{
        
        let lineImage = UIImageView()
        lineImage.image = UIImage(named: "timeline_card_bottom_line")
        return lineImage
    }
}